<template>
	<view>
		<view style="padding-bottom: 50upx;padding-top: 20upx;">
			<view class="list">
				<text style="color: #999;">公司名称</text>
				<view>
					<input type="text" placeholder="填写公司名称" v-model="company_name">
				</view>
			</view>
			<view class="list">
				<text style="color: #999;">所属部门</text>
				<view>
					<input type="text" placeholder="所属部门 " v-model="section">
				</view>
			</view>
			<view class="list">
				<text style="color: #999;">所属职位</text>
				<view>
					<input type="text" placeholder="所属职位" v-model="job_name">
				</view>
			</view>
			<view class="list">
				<text style="color: #999;">在职时间</text>
				<view class="" style="display: flex;">
					<KXDateTime :date='date' :end='enddate' :start='startdate' @rundata='kxdatetime' default='start'
						placeholder="请选择开始时间"></KXDateTime>
					<text style="padding-right: 40px;">至</text>
					<KXDateTime :date='dated' :end='enddated' :start='startdated' @rundata='kxdatetimed' default='start'
						placeholder="请选择结束时间"></KXDateTime>
				</view>
			</view>
			<view class="list">
				<text style="color: #999;">工作内容</text>
				<view>
					<textarea name="" id="" cols="30" rows="10" placeholder="请输入" v-model="job_content"
						style="width: 100%;"></textarea>
				</view>
			</view>
		</view>
		<view
			style="display: flex;width: 100%;background-color: #fff;position: absolute;bottom: 0;height: 80upx;align-items: center;">
			<view class="shanchu" @click="shan">
				删除
			</view>
			<view class="baocun" @click="cun">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	import KXDateTime from "@/components/kx-datetime/kx-datetime.vue"
	export default {
		data() {
			return {
				text: '',
				single: "2021-04-3",
				iszhan: false,
				isZhi: false,
				imageValue: [],
				turl: '',
				iscity: false,
				sex: 0,
				shopId: '',
				titles: '',
				salary: '',
				dianzan: '',
				max: 50,
				nums: 1,
				imglist: [],
				chooseImg: [],
				goodsid: '',
				src: '',
				imageStyles: {
					width: 60,
					height: 60,
				},
				dataList: [],
				types: 'video',
				turl: '',
				tvideo: '',
				zhiweiId: null,
				goodsinfo: {},
				describe: '',
				zhiwei: '请选择',
				xinzi: '请选择',
				imgurl: '',
				spurl: '',
				useid: '',
				startDate: "1900-01-01",
				endDate: "2030-01-01",
				pickerDate: '2022-01-25',
				array: ['选择学历'],
				arrays: ['选择性别', '男', '女'],
				xuelist: [],
				indexw: 0,
				indexd: 0,
				listData: [],
				pickerValueDefault: [0, 0],
				pickerText: '请选择',
				zhilist: [],
				birth: '',
				userinfo: {},
				position_id: '',
				isShow: false,
				upLoadAction: '',
				edu_id: '',
				city_id: '',
				evaluation: '',
				pdfurl: '',
				formData: {},
				topId: '',
				zhenImg: '',
				headerImg: '',
				company_name: '',
				section: "",
				job_name: '',
				start_time: '',
				end_time: '',
				job_content: '',
				datetimerange: ["2010-03-20", "2023-05-10 10:10:10"],
				date: '',
				enddate: '2023-05',
				startdate: '2000-01',
				dated: '',
				enddated: '2023-05',
				startdated: '2000-01',
				sjinfo: {}
			}
		},
		onLoad(option) {
			this.useid = option.useid
			this.sex = option.sex
			this.pickerDate = option.birth
			this.edu_id = option.edu_id
			this.position_id = option.position_id
			this.evaluation = option.evaluation
			this.pdfurl = option.resume_url
			this.salary = option.salary
			this.pickerText = option.pickerText
			this.indexw = option.indexw
			this.zhiwei = option.zhiwei
			this.indexd = option.indexd
			this.user_name = option.user_name
			this.typed = option.type
			this.topId = option.useId
			this.zhenImg = option.zhen_Img
			this.headerImg = option.headImg
			this.sjinfo = JSON.parse(option.sjan)
			console.log(this.sjinfo, "thiss.sjinfothis.sjinfothis.sjinfo")
			this.company_name = JSON.parse(option.sjan).company_name
			this.job_content = JSON.parse(option.sjan).job_content
			this.job_name = JSON.parse(option.sjan).job_name
			this.section = JSON.parse(option.sjan).section
			this.date = JSON.parse(option.sjan).start_time
			this.dated = JSON.parse(option.sjan).end_time
		},
		components: {
			KXDateTime
		},
		watch: {
			datetimesingle(newval) {
				console.log("单选:", this.datetimesingle);
			},
			range(newval) {
				console.log("范围选:", this.range);
			},
			datetimerange(newval) {
				console.log("范围选:", this.datetimerange);
			},
		},
		methods: {
			kxdatetime(e) {
				this.date = e
			},
			kxdatetimed(e) {
				console.log(e,"hehe")
				this.dated = e
			},
			change(e) {
				this.single = e;
				console.log("-change事件:", e);
			},
			shan() {
				var that = this
				this.Loop = setTimeout(function() {

					uni.showModal({
						title: '提示',
						content: '确定删除该工作经历吗？',
						success: function(res) {
							if (res.confirm) {
								that.chule()
							} else if (res.cancel) {
								console.log('用户点击取消');
							}

						}
					});
				}.bind(this), 100);


			},
			chule() {
				this.$http.delnewk({
					job_id: this.sjinfo.id,
				}).then(res => {
					console.log(res.status)
					if (res.status == 200) {
						uni.showToast({
							title: '删除成功',
							icon: 'none'
						})
						setTimeout(() => {
							uni.navigateTo({
								url: `./index?useid=${this.useid}`
							})
						}, 1100)
					}
				})
			},
			cun() {
				var chu = this.date.substring(0, 4)
				var lizhi = this.dated.substring(0, 4)
				
				if (lizhi > chu) {
					let aData = new Date();
					let dateValue = aData.getFullYear() + "-" + (aData.getMonth() + 1) + "-" + aData.getDate();

					var now = dateValue.substring(0, 4)
					if (lizhi > now) {
						uni.showToast({
							title: '离职时间不能选择在今往后的时间',
							icon: "none"
						})
					} else {
						if(chu > now){
							uni.showToast({
								title: '入职时间不能选择在今往后的时间',
								icon: "none"
							})
						}else{
							this.$http.bank({
								id: this.sjinfo.id,
								company_name: this.company_name,
								section: this.section,
								start_time: this.date,
								job_name: this.job_name,
								end_time: this.dated,
								job_content: this.job_content
							}).then(res => {
								console.log(res)
								if (res.status == 200) {
									uni.showToast({
										title: '编辑成功'
									})
									setTimeout(() => {
										uni.navigateTo({
											url: `./index?useid=${this.useid}`
										})
									}, 1500)
								} else {
									uni.showToast({
										title: res.mess
									})
								}
							
							})
						}
					}

				} else {
					uni.showToast({
						title: '离职时间要在入职时间之后',
						icon: "none"
					})
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	uni-input {
		width: 500upx;
	}

	.shanchu {
		width: 140upx;
		height: 72upx;
		background: #F5F5F5;
		border-radius: 10upx;
		margin: 0 auto;
		text-align: center;
		line-height: 72upx;
		border-radius: 5upx;
		color: #333;
	}

	.baocun {
		width: 520upx;
		height: 72upx;
		background: #FF3D3D;
		border-radius: 10upx;
		margin: 0 auto;
		text-align: center;
		line-height: 72upx;
		color: #FFFFFF;
	}

	.xuexiao {
		width: 100%;
		height: 868upx;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		z-index: 6666;
	}

	.header {
		position: fixed;
		background-color: #fff;
		height: 110upx;
		width: 100%;
		top: 40upx;
		left: 0;
		display: flex;
		z-index: 100;
		align-items: center;
		padding-left: 30upx;
	}

	.mask {
		width: 100%;
		height: 100%;
		position: absolute;
		background: rgba(0, 0, 0, 0.2);
		top: 0;
		left: 0;
		z-index: 100;
		cursor: pointer;
		transition: all 0.15s;
	}

	.content {
		width: 100%;
		overflow: hidden;
	}

	.path {
		font-size: 14px;
		word-break: break-all;
	}

	.onelist {
		width: 100%;
		// height: 500upx;
		z-index: 102;
		background-color: #FFFFFF;
		position: fixed;
		// z-index: 66;
		top: 0upx;
		display: flex;
		left: 0;
		padding-bottom: 40upx;
		flex-direction: column;

		.twolist {
			display: flex;
			padding: 30upx;
			justify-content: space-between;
			border-bottom: 2upx solid #EEEEEE;
			width: 100%;
		}
	}

	.tou {
		display: flex;
		width: 100%;
		height: 180upx;
		justify-content: space-between;
		padding: 30upx;
		align-items: center;
		border-bottom: 2upx solid #EEEEEE;
	}

	.list {
		display: flex;
		flex-direction: column;
		padding: 20upx;
		justify-content: center;
		border-bottom: 2upx solid #EEEEEE;

		view {
			padding-top: 15upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			color: #000;
		}
	}
</style>
